home *** CD-ROM | disk | FTP | other *** search
/ CD ROM Paradise Collection 4 / CD ROM Paradise Collection 4 1995 Nov.iso / music / cthugha5.zip / CTHU5SRC.ZIP / GENTABLE.C < prev    next >
C/C++ Source or Header  |  1994-08-19  |  3KB  |  130 lines

  1. //
  2. // Cthugha - Audio Seeded Image Processing
  3. //
  4. // Zaph, Digital Aasvogel Group, Torps Productions 1993-1994
  5. //
  6.  
  7.  
  8. // This is an example program of how to generate rotating tables.
  9. //
  10. // Feel free to change the code, make your own, and send me the 
  11. // resulting .TAB file for inclusion in the next version!!
  12. //
  13. // For more info, check CTHUGHA.DOC (and hope I got around to writing
  14. // that section!
  15. //
  16. // Currently it is configured for a single spiral, with grainy randomness
  17. //
  18.  
  19. #include <stdio.h>
  20. #include <dos.h>
  21. #include <io.h>
  22. #include <fcntl.h>
  23. #include <stdlib.h>
  24. #include <math.h>
  25. #include <conio.h>
  26.  
  27. #include "cthugha.h"
  28.  
  29. unsigned int map;
  30.  
  31. #define M_PI 3.14159265358979323846
  32. #define RADEG (180.0/M_PI)
  33.  
  34. char maptabfile[255];
  35.  
  36. int main(int argc, char **argv)
  37. {
  38.     int x,y,map_x,map_y;
  39.     double polar_r,polar_a;
  40.     double delta_r=2.0,delta_a=0.1;
  41.     double temp_y,temp_x;
  42.     double cent_y,cent_x;
  43.  
  44.     FILE *fp;
  45.  
  46.     argc--; argv++;
  47.     if (argc) {
  48.         strcpy(maptabfile,*argv);
  49.         printf("Generating table: %s\n",maptabfile);
  50.     } else {
  51.         printf("Gentable usage:\n\tgentable tabname.tab <(float)delta_r> <(float)delta_a>\n");
  52.         exit(1);
  53.     }
  54.  
  55.     argc--; argv++;
  56.     if (argc) {
  57.         delta_r=atof(*argv);
  58.     }
  59.     argc--; argv++;
  60.     if (argc) {
  61.         delta_a=atof(*argv);
  62.     }
  63.  
  64.  
  65.     if ((fp=fopen(maptabfile,"wb"))!=NULL) {
  66.         printf("Writing mapping table: %s\n",maptabfile);
  67.         for (y=0; y<BUFF_HEIGHT; y++) {
  68.             printf("%3d/%3d \r",y+1,BUFF_HEIGHT);
  69.  
  70.             for (x=0; x<BUFF_WIDTH; x++) {
  71.                 if (((x==BUFF_WIDTH/4) && (y==BUFF_HEIGHT/2)) ||
  72.                     ((x==3*BUFF_WIDTH/4) && (y==BUFF_HEIGHT/2))) {
  73.                     map=0;
  74.                 } else {
  75.                     cent_y=BUFF_HEIGHT/2;
  76. //                    if (x>BUFF_WIDTH/2) {
  77. //                        cent_x=3*BUFF_WIDTH/4;
  78. //                        temp_x=abs(x-cent_x);
  79. //                    } else {
  80.                         cent_x=BUFF_WIDTH/2;
  81.                         temp_x=abs(x-cent_x);
  82. //                    }
  83.                     temp_y=abs(y-cent_y);
  84.  
  85.                     polar_r=sqrt(temp_x*temp_x + temp_y*temp_y);
  86.                     polar_a=atan2((double)(x-cent_x),(double)(y-cent_y));
  87.  
  88.                     polar_r += delta_r+(rand()%10)*0.01;
  89.  
  90.                     if (polar_r<0)
  91.                         polar_r=0.0;
  92.  
  93.                     polar_a += delta_a+(rand()%10)*0.01;
  94.  
  95. //                    polar_a += (delta_a * (float)(5-(int)(polar_r/11)%11)/5.0);
  96. //                    if (((int)(polar_r/10)%2)) {
  97. //                        polar_a += delta_a;
  98. //                    } else {
  99. //                        polar_a -= delta_a;
  100. //                    }
  101.  
  102.                     temp_y=polar_r*(cosl(polar_a));
  103.                     temp_x=polar_r*(sinl(polar_a));
  104.  
  105.                     map_x=temp_x+cent_x;
  106.                     map_y=temp_y+cent_y;
  107.  
  108.                     if ((map_y>=BUFF_HEIGHT) || (map_y<0) ||
  109.                         (map_x>=BUFF_WIDTH) || (map_x<0) ) {
  110.                         map_x=0;
  111.                         map_y=0;
  112.                     }
  113.  
  114.                     map_x=max(map_x,0);
  115.                     map_y=max(map_y,0);
  116.  
  117.                     map=map_y*BUFF_WIDTH+map_x;
  118.  
  119.                 }
  120.                 fwrite(&map,sizeof(int),1,fp);
  121.             }
  122.         }
  123.  
  124.         fclose(fp);
  125.     }
  126.  
  127. }
  128.  
  129.  
  130.